package com.wpzf.zxhc.controller;

import com.wpzf.common.core.utils.ServletUtils;
import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.common.log.annotation.Log;
import com.wpzf.common.log.enums.BusinessType;
import com.wpzf.common.security.service.TokenService;
import com.wpzf.system.api.model.LoginUser;
import com.wpzf.zxhc.domain.WpCjTbhcjg2023DTO;
import com.wpzf.zxhc.service.CommonService;
import com.wpzf.zxhc.service.WpzfZgTbTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wpzfZgTbTask")
public class WpzfZgTbTaskController {

    @Autowired
    CommonService commonservice;

    @Autowired
    WpzfZgTbTaskService wpzfZgTbTaskServiceImpl;

    @Autowired
    TokenService tokenService;

    @Value("${tempath}")
    public String tempath;

    /*图斑整改*/
    @RequestMapping(value = "/zgSubmit", method = RequestMethod.POST)
    public AjaxResult zgSubmit(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("sh_username", loginUser.getUsername());
        parms.put("sh_realname", loginUser.getSysUser().getNickName());
        Integer rest = wpzfZgTbTaskServiceImpl.zgSubmit(parms);
        if (rest > 0) {
            return AjaxResult.success("图斑整改成功", rest);
        }
        return AjaxResult.error("图斑整改失败", -1);
    }

    @Log(title ="获取整改批次号 *****************核查单位人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_zgtb_pch", method = RequestMethod.POST)
    public AjaxResult query_unit_zgtb_pch(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_zgtb_pch(parms);
        if (rest != null) {
            return AjaxResult.success("批次号获取成功", rest);
        }
        return AjaxResult.error("批次号获取失败", -1);
    }

    @Log(title ="获取所有待整改的图斑 *****************核查单位人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_dzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_user_dzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_user_dzgtb_list(parms);
        Integer cnt = wpzfZgTbTaskServiceImpl.query_unit_user_dzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有待整改的图斑左侧列表 *****************核查单位人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_dzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_unit_user_dzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_user_dzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑*****************核查单位",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_yzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_user_yzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_user_yzgtb_list(parms);
        Integer cnt = wpzfZgTbTaskServiceImpl.query_unit_user_yzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑左侧列表*****************核查单位",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_yzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_unit_user_yzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_user_yzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="获取整改批次号 *****************核查单位负责人",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_pch", method = RequestMethod.POST)
    public AjaxResult query_unit_pch(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_pch(parms);
        if (rest != null) {
            return AjaxResult.success("批次号获取成功", rest);
        }
        return AjaxResult.error("批次号获取失败", -1);
    }

    @Log(title ="获取所有待整改的图斑 *****************核查单位负责人",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_dzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_dzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_dzgtb_list(parms);
        int cnt=wpzfZgTbTaskServiceImpl.query_unit_dzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑 *****************核查单位负责人",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_yzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_yzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_unit_yzgtb_list(parms);
        int cnt=wpzfZgTbTaskServiceImpl.query_unit_yzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="当前图斑进行整改",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/update_unit_zgtb", method = RequestMethod.POST)
    public AjaxResult update_unit_zgtb(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("realname", loginUser.getSysUser().getNickName());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        int rest=wpzfZgTbTaskServiceImpl.update_unit_zgtb(parms);
        if (rest>0) {
            return AjaxResult.success("整改图斑成功", rest);
        }
        return AjaxResult.error("整改图斑失败", -1);
    }

    @Log(title ="获取整改批次号 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_zgtb_pch", method = RequestMethod.POST)
    public AjaxResult query_jl_zgtb_pch(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_jl_zgtb_pch(parms);
        if (rest != null) {
            return AjaxResult.success("监理人员批次号获取成功", rest);
        }
        return AjaxResult.error("监理人员批次号获取失败", -1);
    }

    @Log(title ="获取所有待整改的图斑 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_dzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_jl_user_dzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_jl_user_dzgtb_list(parms);
        Integer cnt = wpzfZgTbTaskServiceImpl.query_jl_user_dzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有待整改的图斑左侧列表 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_dzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_jl_user_dzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_jl_user_dzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑左侧列表 成功", rest);
        }
        return AjaxResult.error("获取所有待整改的图斑左侧列表 失败", -1);
    }

    @Log(title ="获取所有已整改的图斑 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_yzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_jl_user_yzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_jl_user_yzgtb_list(parms);
        Integer cnt = wpzfZgTbTaskServiceImpl.query_jl_user_yzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_yzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_jl_user_yzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfZgTbTaskServiceImpl.query_jl_user_yzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    //整改任务提交
    @Log(title ="整改任务提交",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/zgtbSubmit", method = RequestMethod.POST)
    public AjaxResult zgtbSubmit(@RequestBody Map<String, Object> parm) {
        Integer rest = wpzfZgTbTaskServiceImpl.zgtbSubmit(parm);
        if (rest > 0) {
            return AjaxResult.success("整改任务提交 成功", rest);
        }
        return AjaxResult.error("整改任务提交 失败", -1);
    }

    //整改图斑回显
    @Log(title ="整改图斑回显",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/queryZgtb", method = RequestMethod.POST)
    public AjaxResult queryZgtb(@RequestBody Map<String, Object> parm) {
        WpCjTbhcjg2023DTO rest = wpzfZgTbTaskServiceImpl.queryZgtb(parm);
        if (rest != null) {
            return AjaxResult.success("整改图斑回显 成功", rest);
        }
        return AjaxResult.error("整改图斑回显 失败", -1);
    }

}
